package ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: adol book
 * Date: 2022-04-24
 * Time: 9:06
 */

/**
 *
 * 泛型的上界
 */
/*class Sun<E extends Number>{

}
public class Demo1 {
    public static void main(1String[] args) {
        Sun<Double> sun = new Sun<>();
        Sun<Integer> sun1 = new Sun<>();
        Sun<Float> sun2 = new Sun<>();

    }*/
    class FUN<T extends Comparable<T>> {
        public T findmax(T array[]){
            T max = array[0];
            for (int i = 0; i < array.length; i++) {
                if(max.compareTo(array[i]) < 0){
                    max = array[i];
                }
            }
            return max;
        }
    }
    /**
     *
     * 静态的泛型方法
     */
    class FUN1{
        public static<T extends Comparable<T>>T findmax(T array[]){
            T max = array[0];
            for (int i = 0; i < array.length; i++) {
                if(max.compareTo(array[i]) < 0){
                    max = array[i];
                }
            }
            return max;
        }
    }
public class Demo1 {
    public static void main(String[] args) {
        Integer[] array = {12,34,56};
        Integer max = FUN1.findmax(array); //不需要实例化对象
        System.out.println(max);
    }
    public static void main2(String[] args) {
          FUN <Integer>sun = new FUN<>();
          Integer[] array = {12,34,56};
          Integer max = sun.findmax(array);
        System.out.println(max);

    }
}
